package com.javaeye.chenweihuacwh.web.baseData;

import java.util.List;

import com.javaeye.chenweihuacwh.dto.baseData.ProductCategory;
import com.javaeye.chenweihuacwh.service.baseData.IProductCategoryService;
import com.opensymphony.xwork2.ActionSupport;

public class ProductCategoryAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1998966732318406119L;

	private IProductCategoryService categoryService;
	
	private List categoryList;
	
	private ProductCategory category;
	
	private String categoryId;
	
	public ProductCategoryAction() {
		
	}
	
	public String queryCategoryList() throws Exception {
		categoryList = categoryService.getCategorys();
		return SUCCESS;
	}
	
	public String querySingleCategory() throws Exception {
		category = categoryService.getCategory(categoryId);
		return SUCCESS;
	}
	
	public String saveCategory() throws Exception {
		category = categoryService.saveCategory(category);
		return SUCCESS;
	}
	
	public String deleteCategory() throws Exception {
		boolean success = categoryService.removeCategory(categoryId);
		if (!success) {
			queryCategoryList();
			this.addActionError(getText("actionErrorDeleteProductCategory"));
			return INPUT;
		}
		return SUCCESS;
	}
	
	public void setCategoryService(IProductCategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public List getCategoryList() {
		return categoryList;
	}

	public void setCategoryList(List categoryList) {
		this.categoryList = categoryList;
	}

	public ProductCategory getCategory() {
		return category;
	}

	public void setCategory(ProductCategory category) {
		this.category = category;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}
}
